<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <script src="../script/api.js"></script>
    <style>

    </style>
</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
        <a class="aui-pull-left aui-btn" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle">
            报废确认
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:0px;">
        <ul class="aui-list aui-form-list">
            <!--  <div class="aui-searchbar" id="search" style="position: relative;"> -->
            <!--  <div class="aui-searchbar-input aui-border-radius"> -->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">产线</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择/扫描 产线" id="relMrlCode" value="" onclick="getIdSelector();"
                            onfocus="focusFn(this)" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectMrl()"></i>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
    </div>
    <ul class="ui-selectee" id="tbodyHtml">



    </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>
    var relworkcenter = "";
    var relworkcell = "";
    var relMrlId = "";
    var relMrlCode = "";
    var relMrlName = "";
    var businessType = "";
    var subBusinessType = "";
    var outBusinessType = "";
    var outSubBusinessType = "";
    apiready = function () {
        $("#relMrlCode").focus();
        idSelector = "relMrlCode";
        var query = api.pageParam.query;
        businessType = query.businessType;//需要入库确认的入库业务类型
        subBusinessType = query.subBusinessType;//需要入库确认的入库子业务类型
        outBusinessType = query.outBusinessType;//出库业务类型
        outSubBusinessType = query.outSubBusinessType;//出库子业务类型
        // doSearch();
    }
    function focusFn(ele) {
        $api.attr(ele, 'readonly', 'readonly');
        setTimeout(() => {
            $api.removeAttr(ele, 'readonly');
        }, 200);
    };
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //6：选择物料
    function goSelectMrl() {
        api.openWin({
            name: 'usmSelectLine',
            url: 'usmSelectLine.html',
            pageParam: {
                name: "paScrapCofirm"
            }
        });
    }

    //物料选择后回调函数
    // function setMrl(id, code, name) {
    //     relMrlId = id;
    //     relMrlCode = code;
    //     relMrlName = name;
    //     document.getElementById('relMrlCode').value = code + ":" + name;
    // }

    //产线选择后回调函数
    function setLineCode(id, code, name) {
        relMrlId = id;
        relMrlCode = code;
        relMrlName = name;
        document.getElementById('relMrlCode').value = code + ":" + name;
    }

    //7；PDA自带扫描回车事件-库位
    $("#relMrlCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {
            //物料编码
            $("#relMrlCode").val(sm);
            //校验改箱码是否存在
            getMrl(sm, "relMrlCode");
        }
    });

    //5:库位扫描校验
    function getMrl(code, inputId) {
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdMrlList";
        var data = {
            values: {
                codeQ: code,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    if (list.length == 0) {
                        api.toast({
                            msg: "物料不存在",
                            duration: 6000
                        });
                    } else {
                        relMrlId = list[0].sysid;
                        relMrlCode = list[0].code;
                        relMrlName = list[0].name;
                        document.getElementById(inputId).value = list[0].code + ":" + list[0].name;
                    }


                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 6000
                    });
                    $("#relMrlCode").focus();
                    $("#relMrlCode").select();
                }
            }
        });
    }


    //查询
    function doSearch() {
        //光标所在id
        var idSelector = "";
        if (businessType == "" || businessType == null || businessType == undefined) {
            api.toast({
                msg: '菜单未维护入库业务类型！',
                duration: 6000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getReportNoConfirm";
        var data = {
            values: {
                businessType: businessType,
                subBusinessType: subBusinessType,
                mrlCode: relMrlCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            console.log("ret:" + JSON.stringify(ret));
            if (ret) {
                var data = JSON.stringify(ret);

                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    if (list == null) {
                        return;
                    }
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item  ui-selectee'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>工单号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].work_order_code + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>入库单号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].code + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>报废时间</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].create_date + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>报废人</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].create_id + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].produ_code + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名称</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].produ_name + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>批次号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].lot_code + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].qty + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>箱号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].produ_barcode + "</div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee' " +
                            "onclick='confirmInfo(\"" + list[i].sysid + "\",\"" + list[i].work_center_id + "\",\"" + list[i].work_cell_id + "\",\""
                            + list[i].produ_code + "\",\"" + list[i].lot_code + "\",\"" + list[i].qty + "\",\"" + list[i].tm
                            + "\",\"" + list[i].tmid + "\",\"" + list[i].produ_barcode + "\");'>确认</div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee' " +
                            "onclick='conRefuse(\"" + list[i].sysid + "\",\"" + list[i].work_center_id + "\",\"" + list[i].work_cell_id + "\",\""
                            + list[i].produ_code + "\",\"" + list[i].lot_code + "\",\"" + list[i].qty + "\",\"" + list[i].tm
                            + "\",\"" + list[i].tmid + "\",\"" + list[i].produ_barcode + "\");'>拒绝</div>";
                        html += "</div>";
                        // html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        // html += "<div class='aui-list-item-label ui-selectee list-tr-title'>已绑定数量</div>";
                        // html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].bdQty + "</div>";
                        // html += "</div>";
                        // html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        // html += "<div class='aui-list-item-label ui-selectee list-tr-title' style='width: 45%;'>实际发货数量</div>";
                        // html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 0.1rem;'>" + list[i].actualQty + "</div>";
                        // html += "</div>";
                        // html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        // html += "<div class='aui-list-item-label ui-selectee list-tr-title' style='width: 45%;'>图号</div>";
                        // html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 0.1rem;'>" + list[i].drawing + "</div>";
                        // html += "<div class='aui-list-item-right aui-btn ui-selectee' " +
                        //     "onclick='goPageDetail(\"" + list[i].sysid + "\",\"" + list[i].code + "\",\"" + list[i].invoicedate + "\",\"" + list[i].customerSendCode + "\",\"" + list[i].customerSendName + "\",\"" + list[i].mrlCode + "\",\"" +
                        //     list[i].mrlName + "\",\"" + list[i].planQty + "\",\"" + list[i].actualQty + "\",\"" + list[i].drawing + "\");'>发货</div>";
                        // html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    // console.log("htmlhtml",html);
                    $api.html($api.byId("tbodyHtml"), html);
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 6000
                    });
                }
            }
        });
    }

    function confirmInfo(inBillDetailId, workCenterId, workCellId, produCode, lotCode, qty, tm, tmid, boxnum) {
        api.confirm({
            title: '提示',
            msg: "是否确认选择的报废信息？",
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                save(inBillDetailId, workCenterId, workCellId, produCode, lotCode, qty, tm, tmid, boxnum);
            }
        }
        )

    }

    function conRefuse(inBillDetailId, workCenterId, workCellId, produCode, lotCode, qty, tm, tmid, boxnum) {
        api.confirm({
            title: '提示',
            msg: "是否拒绝选择的报废信息？",
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                back( inBillDetailId,tm);
            }
        }
        )

    }

    //撤销
    function back(inBillDetailId,tm) {

       // const submitButton = document.getElementById('submitButton');
        //submitButton.style.pointerEvents = "none"; // 禁用提交按钮
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyReportReturnSave";
        var data = {
            values: {
                sysid: tm,
                un: un,
                inBillDetailId:inBillDetailId
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });
        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                //submitButton.style.pointerEvents = "auto"; // 启用提交按钮
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                console.log(myobj.code);
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "撤销成功",
                        duration: 6000
                    });

                    //刷新数据
                    doSearch();

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 6000
                    });
                }
            } else {
                //submitButton.style.pointerEvents = "auto"; // 启用提交按钮
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    function save(inBillDetailId, workCenterId, workCellId, produCode, lotCode, qty, tm, tmid, boxnum) {

        if (workCenterId == "" || workCenterId == null || workCenterId == undefined) {
            api.toast({
                msg: '报废信息不完善：仓库信息不存在！',
                duration: 6000
            });
            return;
        }
        if (workCellId == "" || workCellId == null || workCellId == undefined) {
            api.toast({
                msg: '报废信息不完善：库位信息不存在！',
                duration: 6000
            });
            return;
        }
        if (produCode == "" || produCode == null || produCode == undefined) {
            api.toast({
                msg: '报废信息不完善：物料信息不存在！',
                duration: 6000
            });
            return;
        }
        if (lotCode == "" || lotCode == null || lotCode == undefined) {
            api.toast({
                msg: '报废信息不完善：批次信息不存在！',
                duration: 6000
            });
            return;
        }
        if (qty == "" || qty == null || qty == undefined) {
            api.toast({
                msg: '报废信息不完善：数量信息不存在！',
                duration: 6000
            });
            return;
        }
        if (tm == "" || tm == null || tm == undefined) {
            api.toast({
                msg: '报废信息不完善：条码信息不存在！',
                duration: 6000
            });
            return;
        }
        if (tmid == "" || tmid == null || tmid == undefined) {
            api.toast({
                msg: '报废信息不完善：条码信息不存在！',
                duration: 6000
            });
            return;
        }
        if (boxnum == "" || boxnum == null || boxnum == undefined) {
            api.toast({
                msg: '报废信息不完善：条码信息不存在！',
                duration: 6000
            });
            return;
        }
        if (outBusinessType == "" || outBusinessType == null || outBusinessType == undefined) {
            api.toast({
                msg: '菜单未维护报废出库业务类型！',
                duration: 6000
            });
            return;
        }
        if (outSubBusinessType == "" || outSubBusinessType == null || outSubBusinessType == undefined) {
            api.toast({
                msg: '菜单未维护报废出库子业务类型！',
                duration: 6000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/pascrapConfirmSave";
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                businessType: businessType,
                workCenterId: workCenterId,
                workCellId: workCellId,
                produCode: produCode,
                lotCode: lotCode,
                qty: qty,
                tm: tm,
                tmid: tmid,
                boxnum: boxnum,
                outBusinessType: outBusinessType,
                outSubBusinessType: outSubBusinessType,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {

                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    api.hideProgress();

                    api.toast({
                        msg: "保存成功",
                        duration: 6000
                    });

                    doSearch();
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 6000
                    });
                }
            }
        });

    }

    function test() {
        $api.html($api.byId("tbodyHtml"), "");
    }


    //刷新数据
    function refreshData() {
        var dayS = new Date();
        dayS.setTime(dayS.getTime());
        var mm = (dayS.getMonth() + 1) >= 10 ? (dayS.getMonth() + 1) : "0" + (dayS.getMonth() + 1);
        var dd = dayS.getDate() >= 10 ? dayS.getDate() : "0" + dayS.getDate();
        var start =
            dayS.getFullYear() + "-" + mm + "-" + dd;
        doSearch(start);
    }
</script>

</html>